package com.zts.modules.sys.mapper;

import com.zts.base.data.CrudMapper;
import com.zts.modules.sys.entity.Group;
import com.zts.modules.sys.entity.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.session.RowBounds;
import org.springframework.security.access.method.P;

import java.util.List;
import java.util.Map;

/**
 * Created by lily on 2017/6/7.
 */
public interface GroupMapper extends CrudMapper<Group> {
    @Override
    @SelectProvider(type = GroupSqlProvider.class, method = "get")
    Group get(Long id);

    @Override
    @SelectProvider(type = GroupSqlProvider.class, method = "getByEntity")
    List<Group> getByEntity(Group entity);

    @Override
    @SelectProvider(type = GroupSqlProvider.class, method = "getList")
    List<Group> getList(Group entity, RowBounds rowBounds);

    @Override
    @InsertProvider(type = GroupSqlProvider.class, method = "insert")
    @SelectKey(statement = "SELECT currval('seq_user_group_id')", keyProperty = "id", before = false, resultType = Long.class)
    int insert(Group entity);

    @Override
    @UpdateProvider(type = GroupSqlProvider.class, method = "update")
    int update(Group entity);

    @Override
    @DeleteProvider(type = GroupSqlProvider.class, method = "delete")
    int delete(Group entity);

    @SelectProvider(type = GroupSqlProvider.class, method = "getChildren")
    List<Group> getChildren(@Param("id") Long id, @Param("ifDirect") String ifDirect);

    @SelectProvider(type = GroupSqlProvider.class, method = "getUsers")
    List<User> getUsers(@Param("id") Long groupId, @Param("ifDirect") String ifDirect);

    @InsertProvider(type = GroupSqlProvider.class, method = "addUserIntoGroup")
    @SelectKey(statement = "SELECT currval('seq_sys_user_group_id')", keyProperty = "id", before = false, resultType = Long.class)
    int addUserIntoGroup(@Param("userId") Long userId, @Param("groupId") Long groupId,
                         @Param("groupType") String groupType, @Param("sortNum") int sortNum);

    @InsertProvider(type = GroupSqlProvider.class, method = "addUsersIntoGroup")
    @SelectKey(statement = "SELECT currval('seq_sys_user_group_id')", keyProperty = "id", before = false, resultType = Long.class)
    int addUsersIntoGroup(@Param("userIds") List<Long> userIds, @Param("groupId") Long groupId, @Param("groupType") String groupType);

    @SelectProvider(type = GroupSqlProvider.class, method = "checkUserGroupExist")
    boolean checkUserGroupExist(@Param("userId") Long userId, @Param("groupId") Long groupId);

    @DeleteProvider(type = GroupSqlProvider.class, method = "deleteUserFromGroup")
    int deleteUserFromGroup(@Param("userId") Long userId, @Param("groupId") Long groupId);

    @DeleteProvider(type = GroupSqlProvider.class, method = "deleteUsersFromGroup")
    int deleteUsersFromGroup(@Param("userIds") List<Long> userIds, @Param("groupId") Long groupId);

}
